/** \file
* Contains all general-purpose global instances, and the general-purpose entry
* point.
* This file is part of Chorus, available at
* http://code.google.com/p/chorus-twitter/ . This file and all associated files
* and derivative works are bound by the terms of the LGPL 3.0 license,
* available at http://www.gnu.org/licenses/lgpl-3.0-standalone.html .
* \par Subversion URL:
* \$URL: http://chorus-twitter.googlecode.com/svn/branches/cpp/src/system/entry.cpp $
* \version \$Rev: 152 $
* \date    \$Date: 2010-04-06 07:35:13 +0000 (Tue, 06 Apr 2010) $
*/

#include "config.h"

#include <iostream>
#include <fstream>

#include "system/Timer.hpp"

#ifdef WIN32
#	include "system/win32/VCDebugConsole.hpp"
#else
#	include "system/DebugConsole.hpp"
#endif

#include "system/entry.h"

using namespace std;

#ifdef USING_DEBUGCONSOLE
DebugConsole *debugcon = 0;
#endif

#ifdef USING_TIMERGLOB
Timer *timerglob = 0;
#endif

/// The entry point for the application.
/// \return The error level.
bool entry()
{
#ifdef USING_TIMERGLOB
	Timer timer;
	timerglob = &timer;
#endif

#ifdef USING_DEBUGCONSOLE

#ifdef WIN32
	VCDebugConsole con;
#else
	DebugConsole con;
#endif
	debugcon = &con;

	con.addStream(&cerr);
	ofstream log("log.txt");
	con.addStream(&log);
#endif // #ifdef USING_DEBUGCONSOLE

	PDEBUG("Entering mainApp()...");
	bool success = mainApp();
	PDEBUG("Exiting mainApp()...");

#ifdef USING_DEBUGCONSOLE
	debugcon = 0;
#endif

#ifdef USING_TIMERGLOB
	timerglob = 0;
#endif
	return success;
}
